<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增app版本管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-appVersion-add" enctype="multipart/form-data">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">版本号：</label>
                <div class="col-sm-8">
                    <input name="version" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">描述：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">上传文件：</label>
                <div class="col-sm-8">
                    <input id="fileUrl" name="url" type="hidden" value="" required>
                    <div class="file-loading">
                        <input id="file" name="file" type="file" >
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "school/appVersion"
        $("#form-appVersion-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var formData = new FormData($("#form-appVersion-add")[0]);
                var config = {
                    url: prefix + "/add",
                    type: "post",
                    data: formData,
                    async:false,
                    cache:false,
                    contentType:false,
                    processData: false,
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍后...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        $.operate.successCallback(result);
                    }
                };
                $.ajax(config)
              //  $.operate.save(prefix + "/add", $('#form-appVersion-add').serialize());
            }
        }

        $("input[name='createDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
       /* $(document).ready(function() {
            $("#input-700").fileinput({
                uploadUrl: "/common/upload",
                maxFileCount: 5,
                allowedFileExtensions : ['zip','jpg'],//接收文件的后缀
            });
        });*/
        $(document).ready(function () {
            var control = $("#file");
            control.fileinput({
                language:'zh',
                uploadUrl: "/common/uploadFile", // 上传你的地址
                uploadAsync: true, //默认异步上传
                showCaption: true,//是否显示标题
                allowedFileExtensions : ['apk'],//接收文件的后缀
                showUpload:true,//是否显示上传按钮
                enctype: 'multipart/form-data',
                browseClass: "btn btn-primary", //按钮样式
                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                maxFileSize: 15000,
                maxFilesNum: 10,
                maxFileCount:1,
                minFileCount:1,
                layoutTemplates:{
                    actionDelete:"",//去除上传预览缩略图中的删除按钮的缩略图标。
                    actionUpload:"", //去除上传预览缩略图中的上传按钮的缩略图标。
                    actionZoom:""   //去除上传预览缩略图中的查看详情预览的缩略图标。
                },
                //allowedFileTypes: ['image', 'video', 'flash'],
                slugCallback: function(filename) {
                    return filename.replace('(', '_').replace(']', '_');
                }
            }).on("filebatchselected",function(event,files){
                console.log(event);
                console.log(files);

            }).on("fileuploaded",function(event,data,previewId,index){
                if(data.response.code == 0){
                   $("#fileUrl").val(data.response.url)
                }

            }).on("fileerror",function(event,data,msg){
                console.log(event);
                console.log(data);
                console.log(msg);
                $.modal.alertError("上传失败了!");
            });
        });
    </script>
</body>
</html>